# -*- coding: utf-8 -*-

import numpy

from sklearn.model_selection import GridSearchCV

from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier

def create_model(activation='linear'):
    # create model
    model = Sequential()
    model.add(Dense(12, input_dim=8, activation=activation))
    model.add(Dense(1, activation='sigmoid'))
    # Compile model
    model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
    return model

dataset = numpy.loadtxt("data/pima-indians-diabetes.csv", delimiter=",", skiprows=1)
X = dataset[0:,0:8]
Y = dataset[0:,8]

model = create_model()
model.fit(X,Y,batch_size = 40,epochs = 100)

# 验证模型
t = numpy.array([[6,148,72,35,0,33.6,0.627,50]])
print(model.predict(t))